package sync2ck

import (
	"context"
	"flag"
	"github.com/urfave/cli"
	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/logc"
	"github.com/zeromicro/go-zero/core/logx"
	"go-zero-demo/app/datacenter/cron/internal/cmd"
	"go-zero-demo/app/datacenter/cron/internal/config"
	"go-zero-demo/app/datacenter/cron/internal/logic/sync2ck"
	"go-zero-demo/app/datacenter/cron/internal/svc"
)

var OceanMaterialCostJob = cli.Command{
	Name:        "ocean_material_cost",
	Usage:       "数据表（mb_ocean_material_cost）",
	Description: `数据表（mb_ocean_material_cost）`,
	Flags: []cli.Flag{
		cmd.StringFlag("config, c", "etc/cron.yaml", "Custom configuration file path"),
	},
	Action: OceanMaterialCost{}.run,
}

type OceanMaterialCost struct {
	logx.Logger
}

func (a OceanMaterialCost) run(cliCtx *cli.Context) error {
	// 初始化配置文件，实例化service
	flag.Parse()
	//var configFile = flag.String("f", "etc/cron-api.yaml", "the config file")
	configFile := cliCtx.String("config")
	var c config.Config
	conf.MustLoad(configFile, &c)
	logc.MustSetup(c.Log)
	svcCtx := svc.NewServiceContext(c)

	ctx := context.Background()
	server := sync2ck.NewOceanMaterialCost(svcCtx)
	server.Run(ctx)

	return nil
}
